package com.dong.dao;

import com.dong.entity.Dept;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;

import java.util.List;

/**
 * 一对多的配置
 */
public interface IDeptDao {
    @Select("select * from dept where d_id=#{id}")
    @Results(id="dMap",value = {
            @Result(id=true,column = "d_id",property = "did"),
            @Result(column = "d_name",property = "dname"),
            @Result(column = "e_id",property = "e_id"),
            @Result(column = "e_name",property = "e_name"),
            @Result(column = "e_salary",property = "e_salary"),
            @Result(column = "d_id",property = "employees",many = @Many(select = "com.dong.dao.IEmployeeDao.findByDeptId",fetchType = FetchType.LAZY))
    })
    List<Dept> findAll(int id);

    @Select("select * from dept where d_id=#{id}")
    @ResultMap("dMap")
    Dept findById(int id);
}
